package com.qf.mrboot.controller;

import com.qf.mrboot.entity.Subject;
import com.qf.mrboot.result.ResponseData;
import com.qf.mrboot.result.ResultCode;
import com.qf.mrboot.service.SubjectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-06-16 11:12:14
 */
@RestController
@RequestMapping("subject")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Subject selectOne(Integer id) {
        return this.subjectService.queryById(id);
    }


    @ApiOperation(value="queryByTitle",notes = "通过项目标题获取列表")
    @ApiImplicitParam(name="title",value = "项目标题")
    @GetMapping("queryByTitle/{title}")
    public ResponseData queryByTitle(@PathVariable String title) {
        List<Subject> subjects = subjectService.queryByTitle(title);
        return new ResponseData(ResultCode.SUCCESS, subjects);
    }

    @ApiOperation(value="queryById",notes = "通过Id获取数据")
    @ApiImplicitParam(name="id",value = "id")
    @GetMapping("queryById/{id}")
    public ResponseData queryById(@PathVariable Integer id) {
        Subject subject = subjectService.queryById(id);
        return new ResponseData(ResultCode.SUCCESS, subject);
    }

}
